﻿@using System.Configuration
@{
    ViewBag.Title = "Quản Lý Sách";
    Layout = "~/Views/Shared/_Admin_Layout.cshtml";
}
@section CssImport
{
    <style>
        .child-opener-image
        {
            cursor: pointer;
        }
        .child-opener-image-column
        {
            text-align: center;
        }
        .jtable-dialog-form
        {
            min-width: 220px;
        }
        .jtable-dialog-form input[type="text"]
        {
            min-width: 200px;
        }
    </style>
}
<div id="div-main-menu" class="left-side-bar">
    @Html.Partial("_AdminMenu")
</div>
<div id="div-main-content" class="right-side-bar">
    <h2>QUẢN LÝ SÁCH</h2>
    <div class="filtering">
        <form>
            <label>Tên sách:</label> <input type="text" name="bookName" id="bookName" />
            <label>Tác giả:</label> <input type="text" name="bookAuthor" id="bookAuthor" />
            <label>Thể loại:</label> @Html.DropDownList("category", (IEnumerable<SelectListItem>)ViewBag.Categories, new { id = "ID" })
            <button type="submit" id="LoadRecordsButton">Tìm kiếm</button>
        </form>
    </div>

    <div id="LibraryBookContainer">
    </div>
    <script type="text/javascript">

    $(document).ready(function () {
        $('#LibraryBookContainer').jtable({
            title: 'Books List',
            paging: true, //Enable paging
            pageSize: @ConfigurationManager.AppSettings["PageSize"],
            sorting: true, //Enable sorting
            defaultSorting: 'Name ASC',
            //openChildAsAccordion: true, //Enable this line to show child tabes as accordion style
            actions: {
                listAction: '@Url.Action("GetBookList", "Book")',               
                updateAction: '@Url.Action("UpdateBook", "Book")',
                createAction: '@Url.Action("AddBook", "Book")'
            },
            fields: {
                ID: {
                    key: true,
                    create: false,
                    edit: false,
                    list: false
                },
                BookCode: {
                    title: 'Mã sách'
                },
                BookName: {
                    title: 'Tên sách'
                },
                BookAuthor: {
                    title: 'Tác giả'       
                },
                BookCategory:{
                    title: 'Thể loại',
                    options: '@Url.Action("CategoryOptions", "Category")'
                },
                BookQuantity: {
                    title: 'Số lượng'
                },
                PricePerUnit: {
                    title: 'Giá tiền',
                    sorting: false
                },
                Storage: {
                    title: 'Lưu trữ',
                    sorting: false
                },
                Description: {
                    title: 'Mô tả',
                    type: 'textarea',
                    list: false
                },
                IsContainDisk: {
                    title: 'Kèm đĩa',
                    type: 'checkbox',
                    values: { 'false': 'Sách không kèm theo đĩa', 'true': 'Sách kèm theo đĩa' },
                    defaultValue: 'false',
                    sorting: false
                },
                Photo: {
                    title: 'Photo',
                    type: 'image',
                    list: false,
                    sorting: false
                },
                FirstInputedDate: {
                    title: 'Ngày nhập',
                    type: 'date',
                    displayFormat: 'dd-mm-yy',
                    list: false
                },
                BorrowTimes: {
                    title: 'Lần mượn',
                    create: false,
                    edit: false
                },               
            },
            //validate cac field trong bang Libraty_Books
            formCreated: function (event, data) {
                data.form.find('input[name="BookCode"]').addClass('validate[required]');
                data.form.find('input[name="BookName"]').addClass('validate[required]');
                data.form.find('input[name="BookAuthor"]').addClass('validate[required]');

                data.form.find('input[name="BookQuantity"]').addClass('validate[required,custom[number]]');
                data.form.find('input[name="PricePerUnit"]').addClass('validate[required,custom[number]]');
                data.form.find('input[name="Storage"]').addClass('validate[required]');
                data.form.find('input[name="Description"]').addClass('validate[required]');
                data.form.find('input[name="Photo"]').addClass('validate[required]');
                data.form.find('input[name="BorrowTimes"]').addClass('validate[required,custom[number]]');
                data.form.validationEngine();
            },
            formSubmitting: function (event, data) {
                return data.form.validationEngine('validate');
            },
            formClosed: function (event, data) {
                data.form.validationEngine('hide');
                data.form.validationEngine('detach');
            },
        });

        //Load person list from server
        $('#LoadRecordsButton').click(function (e) {
            e.preventDefault();
            $('#LibraryBookContainer').jtable('load', {
                bookAuthor: $('#bookAuthor').val(),
                bookName: $('#bookName').val(),
                category: $('#ID').val(),
            });
        });

        //Load all records when page is first shown
        $('#LoadRecordsButton').click();
    });
    </script>

</div>
<div style="clear: both"></div>